<template>
	<view>
		<view class="list gray">群主</view>
		<view class="list list1">
			<view class="list2" v-for="(item, index) in zhu" :key='index'>
				<image class="head_img" v-bind:src="item.member.avatar?item.member.avatar:avatar"></image>
				<view class="name">{{item.member.nickname}}</view>
			</view>
		</view>
		<view v-if="!arrList.length" class="list nulls gray">你还没有设置管理员</view>
		<view v-if="arrList.length" class="list gray">管理员</view>
		<view class="list list1" v-for="(item, index) in arrList" :key='index'>
			<view class="list2">
				<image class="head_img" v-bind:src="item.member.avatar?item.member.avatar:avatar"></image>
				<view class="name">{{item.member.nickname}}</view>
			</view>
			<image class="yichu" @click="del(item.user_id)" src="../../static/image/yichu_42.png"></image>
		</view>
		<view class="fixed" @click="addAdministrator">添加管理员</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '123',
				arrList:1,
				group_id:'',
				avatar:uni.getStorageSync('noavatar'),
				zhu:[]
			}
		},
		onLoad(options){
			this.group_id = options.group_id;
			//this.initDat();
			// uni.onSocketMessage(function (res) {
			//   console.log('收到服务器内容：' + res.data);
			// });
		},
		onShow(){
			this.$msgchat.initwork();
			this.getguan();
			this.getzhu();
			
		},
		methods: {
			getzhu(){
				var obj = {
					token: uni.getStorageSync('token'),
					group_id:this.group_id,
					type:3
				}
				this.$common.requests('/api/Group/groupmemberlist', obj).then(res => {
					if(res.data.code==1){
						for(var i=0;i < res.data.data.length;i++ ){
							// this.avatar = res.data.data[i].userinfo.avatar;
							if(res.data.data[i].member.avatar){
								res.data.data[i].member.avatar =  this.$common.baseUrl + res.data.data[i].member.avatar;
							}else{
								res.data.data[i].member.avatar = '';
							}
							
						}
						this.zhu = res.data.data;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			getguan(){
				var obj = {
					token: uni.getStorageSync('token'),
					group_id:this.group_id,
					type:2
				}
				this.$common.requests('/api/Group/groupmemberlist', obj).then(res => {
					console.log(res)
					if(res.data.code==1){
						for(var i=0;i < res.data.data.length;i++ ){
							// this.avatar = res.data.data[i].userinfo.avatar;
							if(res.data.data[i].member.avatar){
								res.data.data[i].member.avatar =  this.$common.baseUrl + res.data.data[i].member.avatar;
							}else{
								res.data.data[i].member.avatar = '';
							}
							
						}
						this.arrList = res.data.data;
					}else{
						this.$api.msg(res.data.msg);
						return;
					}
					
				})
			},
			del(id){
				var that = this;
				uni.showModal({
				    title: '',
				    content: '确认取消他的管理员身份？',
				    success: function (res) {
				        if (res.confirm) {
							var obj = {
								token: uni.getStorageSync('token'),
								group_id:that.group_id,
								people:id
							}
							// console.log(obj);return false;
							that.$common.requests('/api/Group/delgroupmanage', obj).then(res => {
								console.log(res)
								if(res.data.code==1){
									that.$api.msg(res.data.msg);
									that.getguan();
									return;
								}else{
									that.$api.msg(res.data.msg);
									return;
								}
								
							})
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			},
			//添加管理员
			addAdministrator(){
				uni.navigateTo({
					url:'../addAdministrator/addAdministrator?group_id='+this.group_id
				})
			}

		}
	}
</script>

<style>
	page {
		background: #F5F4F9;
	}

	.list {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30upx;
		letter-spacing: 3upx;
	}

	.gray {
		color: #787878;
	}

	.list1 {
		background: #FFF;
		padding:15upx 30upx;
	}

	.list2{
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}
	.name{
		margin-left: 15upx;
	}
	.head_img{
		width: 100upx;
		height: 100upx;
		border-radius: 50%;
	}
	.nulls{
		text-align: center;
		justify-content: center!important;
		margin: 100upx 0;
	}
	.yichu{
		width: 50upx;
		height: 50upx;
	}
	.fixed{
		padding: 30upx 0;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		text-align: center;
		background: #FFF;
	}
</style>
